package easy;

public class Solution_520 {

    public boolean detectCapitalUse(String word) {
        char[] chars = word.toCharArray();
        boolean preUp = false;
        for (int i = 0; i < chars.length; i++) {
            if (chars[i] <= 90 && chars[i] >= 65) {
                // 当前字母是大写
                if (i > 0 && !preUp) {
                    // 前一个是小写
                    return false;
                }
                preUp = true;
            } else {
                // 当前字母是小写
                if (preUp && i != 1) {
                    // 前一个非首位字母是大写
                    return false;
                }
                preUp = false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        Solution_520 model = new Solution_520();
        System.out.println(model.detectCapitalUse("USA"));
        System.out.println(model.detectCapitalUse("usa"));
        System.out.println(model.detectCapitalUse("Usa"));
        System.out.println(model.detectCapitalUse("UsA"));
        System.out.println(model.detectCapitalUse("uSa"));
        System.out.println(model.detectCapitalUse("FFFFFFFFFFFFFFFFFFFFf"));
        System.out.println(model.detectCapitalUse("Leetcode"));
        //        System.out.println('A'-0);
        //        System.out.println('Z'-0);
    }
}
